const baseUrl = 'http://192.168.31.198:9999/';

export const request = (options) => {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + options.url,
			method: options.method || 'GET',
			data: options.data || 0,
			header: {
				'Content-Type': 'application/json',
				 // 可添加token等认证信息
				'token': uni.getStorageSync('token')
			},
			success: (res) => {
				if (res.statusCode === 200) {
					resolve(res.data);
				} else {
					reject(new Error(`请求失败: ${res.statusCode}`));
				}
			},
			fail: (err) => {
				reject(err);
			}
		});
	});
};

// 导出baseUrl，方便上传图片等其他场景使用
request.baseUrl = baseUrl;
export default request;